<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class C_room extends CI_Controller {

	function __construct()
	{
        parent::__construct();
        $this->load->model('room');

        $this->title = "Great spacious rooms in resort on Siem Reap River : Lynnaya Boutique Hotel";
        $this->meta_title = "Great spacious rooms in resort on Siem Reap River : Lynnaya Boutique Hotel";
        $this->meta_keywords = "images of rooms in siem reap, visit our urban resort";
        $this->meta_description = "Preferred rates on rooms at Lynnaya Hotel, located on the riverbanks of Siem Reap in Cambodia";
	}

    public function index()
    {
        $data = array();
        $data['results'] =$this->room->getRoomList();

        $this->load->view('lyn/room/v_list', $data);
    }

    public function booking()
    {
        if( $this->input->post('form_value') == "" || !is_numeric($this->input->post('form_value')) )
            redirect();

        $room_name = $this->input->post('room_name');
        $name = $this->input->post('name');
        $email = $this->input->post('email');
        $nationality = $this->input->post('nationality');
        $check_in = $this->input->post('check_in');
        $check_out = $this->input->post('check_out');
        $guest = $this->input->post('guest');
        $pick_up = $this->input->post('pick_up');

        $subject_admin = "New booking from website";
        $header_admin = '
            <table width="585px" border="0" cellspacing="0" cellpadding="5" style="padding:10px; margin-top:10px; font-size: 11px; color: #000;">
            <tr>
                <td colspan="2">
                    <img src="'.base_url().'public/images/icon-l-logo.png" align="left" style="padding-right:30px;" />
                    <span style="color:#371815; font-size:28px;">BOOKING AT LYNNAYA HOTEL<span>
                </td>
            </tr>
        ';

        $body_tour = '

			<tr>
			    <td align="right" style="border-top: 1px solid #B9442F; border-bottom: 1px solid #B9442F; color:#371815; font-size:15px; padding-right: 30px;">
			        <span style="color:#B9442F;">LYN</span>'.strtoupper($room_name).'
			    </td>
			    <td style="border-top: 1px solid #B9442F; border-bottom: 1px solid #B9442F;"></td>
			</tr>
		';

        $body_info = '
          <tr height="5px"></tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">NAME</td>
			<td valign="top" width="340px"> '.$name.'</td>
		  </tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">EMAIL ADDRESS</td>
			<td valign="top" width="340px"> '.$email.'</td>
		  </tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">NATIONALITY</td>
			<td valign="top" width="340px"> '.$nationality.'</td>
		  </tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">CHECK-IN DATE</td>
			<td valign="top" width="340px"> '.date('d-M-Y', strtotime($check_in)).'</td>
		  </tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">CHECK-OUT DATE</td>
			<td valign="top" width="340px"> '.date('d-M-Y', strtotime($check_out)).'</td>
		  </tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">NUMBER OF GUEST(S)</td>
			<td valign="top" width="340px"> '.$guest.'</td>
		  </tr>
		  <tr>
			<td align="right"  width="200px" valign="top" style="color:#B9442F; padding-right: 30px;">PICK UP</td>
			<td valign="top" width="340px"> '.$pick_up.'</td>
		  </tr>
          <tr height="5px"></tr>
		  <tr>
		    <td colspan="2" valign="middle" style="border-top: 1px solid #B9442F; border-bottom: 1px solid #B9442F; ">
		        <img src="'.base_url().'public/images/icon-s-logo.png" align="left" style="padding-right:20px;" />
		        <span>Good Day, thank you for booking your stay with us. Let us check that the room is available at these dates and we will confirm within the next hour or so.<span>
		    </td>
		  </tr>

		</table>';

        $body_admin = $header_admin.$body_tour.$body_info;

        $email = $email;

        $this->load->library('email');
        $this->email->set_mailtype("html");

        // for admin
        $this->email->from($email, $name);
        $this->email->to('reservation@lynnaya.com');
        //$this->email->to('psthea@gmail.com');
        $this->email->bcc('sokthea@impact-cambodia.com, info@lox-design.com');
        $this->email->subject($subject_admin);
        $this->email->message($body_admin);
        $ok = $this->email->send();

        if( $ok )
        {
            $data['message'] = "
                <div class='message'>
                    <p class='pb10'>Dear ".$name.",</p>

                    <p>
                    Thank you for booking a LynSuite with us, your request has been sent to our reservation officer.<br />
                    Please expect a confirmation within the next hours.
                    </p>
                </div>
            ";
        }
        else
        {
            $data['message'] = "
                <div class='message'>
                    <p>Unsuccess!</p>
                </div>
            ";
        }


        //$data['tour_name'] = $room_name;

        header('Content-Type: application/x-json; charset=utf-8');
        echo(json_encode($data['message']));

        //trace($this->email);
        //trace($data);
        //exit;

        //$this->load->view('sejour/booking-sucess', $data);
    }

}
